package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.core.pojo.entity.UserBind;
import com.atguigu.srb.core.service.UserBindService;
import com.atguigu.srb.core.service.UserInfoService;
import com.atguigu.srb.result.ResponseVo;
import com.atguigu.srb.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户绑定表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/api/core/userBind")
public class ApiUserBindController {
    @Autowired
    private UserBindService userBindService;
    @Resource
    private UserInfoService userInfoService;
    @ApiOperation("查看用户绑定状态")
    @GetMapping("/status")
    public ResponseVo getBindStatus(@RequestHeader("token") String token){
        Long userId = JwtUtils.getUserId(token);
        Integer status = userBindService.getById(userId).getStatus();
        return ResponseVo.ok().addData("item",status);
    }
    @ApiOperation("绑定银行卡到hfb")
    @PostMapping("/bind")
    public ResponseVo bindHfb(@RequestHeader("token") String token, @RequestBody UserBind userBind){
            String formAutoCommit = userBindService.bindHfb(token,userBind);
            return ResponseVo.ok().addData("form",formAutoCommit);
    }

    @ApiOperation("绑定hfb成功后,hfb通知我们的项目的接口")
    @PostMapping("/notify")
    public String  hfbNotify(HttpServletRequest request){
        return userBindService.hfbNotify(request);
    }

}

